#函数与模块

#写文件
"""file_object=open('t1.txt',mode='wb')
file_object.write("xiaofeng".encode('utf-8'))
file_object.close()

file_object=open('t1.txt',mode='wt',encoding='utf-8')#encoding='utf-8'可以省略，默认会以utf-8形式压缩
file_object.write("王")
file_object.close()
file_object=open('t1.txt',mode='at+',encoding='utf-8')#encoding='utf-8'可以省略，默认会以utf-8形式压缩
file_object.write("王xx")
file_object.close()"""

#写图片
"""f1=open("user.png",mode='rb')
content=f1.read()
f1.close()
f2=open("test.png",mode='wb')
f2.write(content)
f2.close()"""

#注意事项
"""
1、 w写入文件，先清空文件；再在文件中写入文件（会覆盖掉原文件的内容）：追加/每次写的时候只需要打开一次文件
2、 + 表示即可读又可写
"""

#利用python 向某个网址发送请求并获取结果(利用第三方的模块)
"""import requests
res=requests.get(
    url="https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=20",
    headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
)
file_object=open('file\\t1.txt',mode='wb')
file_object.write(res.content)
file_object.close()
"""
"""import requests
res=requests.get(
    url="https://hbimg.huabanimg.com/c7e1461e4b15735fbe625c4dc85bd19904d96daf6de9fb-tosv1r_fw1200",
    headers={ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
)
file_object=open('file\\美女.png',mode='wb')
file_object.write(res.content)
file_object.close()"""

"""file_object=open('file\\info.txt',mode='rt+')
#读取内容
data=file_object.read()
print(data)
#写入内容
file_object.write("root")
file_object.close()"""

file_object=open('file\\info.txt',mode='rt+')

file_object.write("xiao")

file_object.seek(0)  #光标位置重置到开始的位置
data=file_object.read()
print(data)


file_object.close()